import com.neuedu.mybatis.po.Dept;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.List;

/**
 * @author 金山
 * 项目：mybatis-learn
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/3/410:54
 */
public class HelloWorld {

    public static void main(String[] args) throws IOException {

        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);


        //创建session对象
        SqlSession session = sqlSessionFactory.openSession();


        //使用 session  执行sql语句


        List<Dept> deptList = session.selectList("test.selectDept");

        deptList.forEach(System.out::println);


        /**
         * 1 Class.forName("com.mysql.cj.jdbc.Driver")
         *
         * 2 连接
         *    conn = Drivermanger.getConnection(url,user,password)
         *
         * 3  创建Statement
         *     stmt =  conn.createStatement()
         *  4 执行sql
         *   stmt。executeQuery  --》 select
         *    stmt.executeUpdate -->  update\insert\delete
         *   5 select 需要解析查询结果接  ResultSet
         *
         *   6 更新  --- commit
         *
         *  7  关闭资源  rs   stmt  conn
         *
         */

        Connection conn = null;

    }
}
